SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO


CREATE VIEW dbo.[DnnProduct_vw_Portals]
AS
	SELECT DISTINCT 
		P.PortalID,
		P.PortalGroupID, 
		PL.PortalName, 
		CASE WHEN LEFT(LOWER(PL.LogoFile), 7) = 'fileid=' THEN
				(SELECT Folder + FileName FROM dbo.DnnProduct_Files WHERE fileid = CAST((RIGHT(LOWER(PL.LogoFile), Len(PL.LogoFile) - 7)) AS int)) 
			ELSE 
				PL.LogoFile 
			END AS LogoFile, 
		PL.FooterText, 
		P.ExpiryDate, 
		P.UserRegistration, 
		P.BannerAdvertising, 
		P.AdministratorId, 
		P.Currency, 
		P.HostFee, 
		P.HostSpace, 
		P.PageQuota, 
		P.UserQuota, 
		P.AdministratorRoleId, 
		P.RegisteredRoleId, 
		PL.Description, 
		PL.KeyWords, 
		CASE WHEN LEFT(LOWER(PL.BackgroundFile), 7) = 'fileid=' THEN
				(SELECT Folder + FileName FROM dbo.DnnProduct_Files WHERE fileid = CAST((RIGHT(LOWER(PL.BackgroundFile), Len(PL.BackgroundFile) - 7)) AS int)) 
			ELSE 
				PL.BackgroundFile 
			END AS BackgroundFile, 
		P.GUID, 
		P.PaymentProcessor, 
		P.ProcessorUserId, 
		P.ProcessorPassword, 
		P.SiteLogHistory, 
		U.Email, 
		P.DefaultLanguage, 
		P.TimezoneOffset, 
		PL.AdminTabId, 
		P.HomeDirectory, 
		PL.SplashTabId, 
		PL.HomeTabId, 
		PL.LoginTabId, 
		PL.RegisterTabId, 
		PL.UserTabId, 
		PL.SearchTabId,
		(SELECT  TOP (1) TabID
			FROM   dbo.DnnProduct_Tabs
				WHERE      (PortalID IS NULL) AND (ParentId IS NULL))
			AS SuperTabId, 
		P.CreatedByUserID, 
		P.CreatedOnDate, 
		P.LastModifiedByUserID, 
		P.LastModifiedOnDate, 
		PL.CultureCode
	FROM dbo.DnnProduct_Portals AS P 
		INNER JOIN dbo.DnnProduct_PortalLocalization AS PL ON P.PortalID = PL.PortalID 
		LEFT OUTER JOIN dbo.DnnProduct_Users AS U ON P.AdministratorId = U.UserID
GO
